package com.rrd.dw.mr.gzip.kafka;

import java.io.IOException;
import java.util.Date;
import java.util.regex.Pattern;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rrd.dw.utils.DateUtil;
import com.ucredit.babel.common.model.Job;
import com.ucredit.babel.common.model.nifa.NifaData;
import com.ucredit.babel.common.model.third.bairong.BairongData;
import com.ucredit.babel.common.model.third.bairong.BairongRecord;

/**
 * 百融策略引擎
 * @author liubaoxin
 */
@Deprecated
public class BairongParse {
	public static final String CRT001 =  "\001";
	public static final Pattern CRT001_PATTERN =  Pattern.compile("\001");
	private String timestamstr="";
	private String job_id ="";
	private String system_id ="";
	private StringBuilder sb = new StringBuilder(500);
	private  Text val = new Text();
	 private Text key_text = new Text("bairong_data");

	
	/**
	 * 百融策略引擎数据
	 * @param userBehavior
	 * @throws InterruptedException 
	 * @throws IOException 
	 */
	public  void parseBairong(Context context,BairongRecord bairongRecord) throws IOException, InterruptedException{
		 
    	Job job = bairongRecord.getJob();
    	BairongData bairongData = bairongRecord.getData();
    	 
    	sb.delete(0,sb.length());
    	//job_id
    	this.job_id = job.getJobID()==null?"":job.getJobID();
    	//system_id
    	this.system_id = job.getSystemID()==null?"":job.getSystemID().toString();
    	//数据时间 
    	this.timestamstr=bairongRecord.getTimestamp()==null?"":DateUtil.formateDateStr(new Date(bairongRecord.getTimestamp()));
 
    	sb.append(job_id).append(CRT001);
    	sb.append(system_id).append(CRT001);
    	sb.append(this.timestamstr).append(CRT001);
    	
    	sb.append(bairongData.getName()==null?"":bairongData.getName()).append(CRT001);
    	sb.append(bairongData.getIdCard()==null?"":bairongData.getIdCard()).append(CRT001);
    	sb.append(bairongData.getMobile()==null?"":bairongData.getMobile()).append(CRT001);
    	sb.append(bairongData.getData()==null?"":bairongData.getData()).append(CRT001);
    	//爬取开始时间
    	sb.append(job.getStartTime()==null?"":DateUtil.formateDateStr(job.getStartTime())).append(CRT001);
    	//爬取结束时间
    	sb.append(job.getEndTime()==null?"":DateUtil.formateDateStr(job.getEndTime()));
    	val.set(sb.toString());
        context.write(key_text, val);
    
    	 
	}
	
	
	
	
	
}
